package com.service;

import java.util.List;

import com.dao.PackagesDAO;
import com.dao.PackagesInfoDAO;
import com.domain.PackagesInfo;
import com.domain.Packages;

public class PackagesService {
	public void insertPackage(PackagesInfo packageInfo, List<Packages> packages) {
		PackagesInfoDAO productInfoDAO = new PackagesInfoDAO();
		PackagesDAO packageDAO = new PackagesDAO();
		productInfoDAO.insert(packageInfo);
		for (Packages p : packages) {
			packageDAO.insert(p);
		}
	}
	public int deletePackage(String code) {
		PackagesInfoDAO packageInfoDAO = new PackagesInfoDAO();
		PackagesInfo packageinfo = getPackageInfoById(code);
		PackagesDAO packageDAO = new PackagesDAO();
		if (packageinfo != null) {
			packageDAO.deletePackageByPackageId(code);
			packageInfoDAO.deletePackageInfoByPackageId(code);
			return 1;
		}
		else {
			return 0;
		}		
	}
	public PackagesInfo getPackageInfoById(String code) {
		PackagesInfoDAO dao = new PackagesInfoDAO();
		return dao.getPackageInfoById(code);
	}
	public List<PackagesInfo> getAllPackageInfo() {
		PackagesInfoDAO packageInfoDAO = new PackagesInfoDAO();
		return packageInfoDAO.getAllPackageInfo();
	}
}
